<template>
	<view class="login">
		<view class="login-box">
			<view class="login-avatar">

			</view>
			<view class="login-btn-box">
				<view class="login-btn" @tap="toUcenter">使用语若账号登陆</view>
				<view></view>
			</view>
			<view class="other-line-box">
				<hr class="other-line">
				<view class="other-font">其他登陆方式</view>
				<hr class="other-line">
			</view>
			<view class="other-login-way">
				<text>手机号登陆(暂不支持)</text>
				<text>会员账号登陆(暂不支持)</text>
			</view>
		</view>
	</view>
</template>

<script>
	import $http from '@/common/api/request.js'
	export default {
		data() {
			return {

			}
		},
		onLoad(options) {
			if (options.code) {
				let code = options.code
				this.getToken(code)
			}
		},
		methods: {
			toUcenter() {
				location.href = $http.common.ucenterUrl + window.location.href.replace('/#', '')
			},
			getToken(code) {
				uni.removeStorageSync('access_token')
				$http.request({
					url: `/webapp/auth/token/${code}`
				}).then(res => {
					uni.setStorageSync('access_token', res.data.access_token)
					this.getMemberInfo()
				})
			},
			getMemberInfo() {
				$http.request({
					url: `/member/member/info`
				}).then(res => {
					uni.setStorageSync('userinfo', res.data)
					uni.showToast({
						duration: 1000,
						title: '登陆成功，欢迎' + res.data.username,
						icon: 'none'
					})
				})
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/index/index'
					})
				}, 1000)
			}
		}
	}
</script>

<style scoped>
	.login-btn-box {
		margin-top: 650rpx;
		width: 100%;
		height: 100rpx;
	}

	.login-btn {
		width: 80%;
		height: 80rpx;
		text-align: center;
		margin: 0 auto;
		line-height: 80rpx;
		background-color: #FD1C00;
		color: #FFFFFF;
		border-radius: 20rpx;
		font-size: 26rpx;
		font-weight: 800;
	}

	.other-line-box {
		display: flex;
		justify-content: space-between;
		width: 90%;
		text-align: center;
		margin: 0 auto;
		height: 20rpx;
		margin-top: 80rpx;
		height: 20rpx;
		line-height: 20rpx;
	}

	hr {
		height: 3rpx;
		margin: auto;
		background-color: #E5E5E5;
		border: none;
		width: 30%;
	}

	.other-font {
		font-size: 26rpx;
		color: #CCCCCC;
	}

	.other-login-way {
		font-size: 28rpx;
		color: #999999;
		text-decoration: underline;
		display: flex;
		justify-content: space-between;
		width: 90%;
		margin: 60rpx auto;
	}
</style>